<!--
 * @Author: your name
 * @Date: 2021-08-03 13:35:26
 * @LastEditTime: 2021-08-11 22:25:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \getHome (2)\src\components\discounts\coupon.vue
-->
<!--优惠券发放/使用记录-->
<template>
  <div class="content">
    <div class="herdertop">
      <img src="../../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>优惠卷管理</el-breadcrumb-item>
        <el-breadcrumb-item b-item>优惠券发放/使用记录</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center" style="padding-top: 0px;">
      <div class="hander">优惠券发放/使用记录</div>

      <div class="entirety">
        <div class="search">
          <!--  账号状态搜索信息 -->

          <div class="demo-input-suffix">
            优惠券状态

            <el-select v-model="value" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
          <div class="news">
            <div class="userSearch">
              <el-select v-model="select" placeholder="请选择" @change="sel">
                <el-option
                  v-for="item in options1"
                  :key="item.value1"
                  :label="item.label1"
                  :value="item.value1"
                >
                </el-option>
              </el-select>
              <el-input v-model="input" placeholder="请输入"></el-input>
            </div>
          </div>
          <!--  账号状态搜索信息 -->
          <div class="demo-input-suffix" style="margin-right:35px">
            <el-button
              style="background-color:#fd804c;color: #fff;"
              @click.native.prevent="isSelect"
              >查询</el-button
            >
            <el-button type="warning" @click.native.prevent="isEmpty"
              >清空</el-button
            >
          </div>
          <div class="news">
            <el-button size="medium" @click="addCoupon">新建优惠券</el-button>
          </div>
        </div>
      </div>

      <div class="tab">
        <el-table :data="dataList">
          <el-table-column type="selection" width="50"> </el-table-column>
          <el-table-column label="优惠券ID" prop="couponCode">
          </el-table-column>
          <el-table-column label="优惠券名称" prop="couponTitle">
          </el-table-column>
          <el-table-column label="用户昵称" prop="nickName"> </el-table-column>
          <el-table-column label="用户手机号" prop="phone"> </el-table-column>
          <el-table-column label="有效期" prop="effectiveStartTime" width="180">
            <template slot-scope="scope">
              <div>
                {{ scope.row.effectiveStartTime }}-
                {{ scope.row.effectiveEndTime }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="优惠券状态" prop="couponStatus">
            <template slot-scope="scope">
              <span v-if="scope.row.couponStatus === 0">未使用</span>
              <span v-else-if="scope.row.couponStatus === 1">已使用</span>
              <span v-else>已过期</span>
            </template>
          </el-table-column>
          <el-table-column label="订单编号" prop="orderNo"> </el-table-column>
        </el-table>
      </div>
      <div class="block">
        <div class="left"></div>
        <div class="right">
          <el-pagination
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            :page-size="pageSize"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      options: [
        {
          value: "",
          label: "全部"
        },
        {
          value: 0,
          label: "未使用"
        },
        {
          value: 1,
          label: "已使用"
        },
        {
          value: 2,
          label: "已过期"
        }
      ],
      value: "",

      options1: [
        {
          value1: 1,
          label1: "优惠券名称"
        },
        {
          value1: 2,
          label1: "订单编号"
        },
        {
          value1: 3,
          label1: "用户昵称"
        },
        {
          value1: 4,
          label1: "用户手机号"
        }
      ],
      value1: "",

      input: "",
      couponTitle: "",
      memberPhone: "",
      memberNickName: "",
      couponNo: "",
      select: 1,
      total: 0,
      pageNum: 1, //当前页码
      pageSize: 20, //每页显示的个数
      list: [],
      dataList: [],
      search: "",
      dialogFormVisible: false,
      form: {
        project: "",
        location: "",
        comment: "",
        name: "",
        phone: "",
        id: ""
      },
      formLabelWidth: "120px",
      dialogStatus: "create"
    };
  },
  created() {
    this.getCouponSendInfos();
  },
  methods: {
    isSelect() {
      // this.getCouponSendInfos();
      if (this.select === 1) {
        this.couponTitle = this.input;
      } else if (this.select === 2) {
        this.orderNo = this.input;
      } else if (this.select === 3) {
        this.memberNickName = this.input;
      } else if (this.select === 4) {
        this.memberPhone = this.input;
      } else {
        this.orderNo = this.input;
      }

      (this.pageNum = 1), (this.pageSize = 20), this.getCouponSendInfos();
    },

    isEmpty() {
      (this.value = ""),
        (this.value1 = ""),
        (this.input = ""),
        (this.couponTitle = ""),
        (this.memberPhone = ""),
        (this.memberNickName = ""),
        (this.couponNo = ""),
        (this.select = 1),
        (this.pageNum = 1), //当前页码
        (this.pageSize = 20), //每页显示的个数
        (this.search = ""),
        this.getCouponSendInfos();
    },
    addCoupon() {
      this.$router.push({
        path: "/amend"
      });
    },
    // 你的总数据.slice((当前页码—1)*每页显示的个数)，（当前页码*每页的个数）,
    handleSizeChange(val) {
      //改变每页显示的个数
      //console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.pageNum = 1;

      this.getCouponSendInfos();
    },
    handleCurrentChange(val) {
      //改变当前页码
      //console.log(`当前页: ${val}`);
      this.pageNum = val;

      this.getCouponSendInfos();
    },
    but() {
      //console.log(this.select);
    },
    sel(val) {
      ((this.couponTitle = ""),
      (this.memberPhone = ""),
      (this.memberNickName = ""),
      (this.orderNo = "")),
        (this.input = "");
    },
    changeStatus(val) {
      this.value = val;
      this.pageNum = 1;
      this.getCouponSendInfos();
    },
    getCouponSendInfos() {
      this.$http({
        url: "/couponadmin/v1/couponSend/getCouponSendInfos",
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          memberNickName: this.memberNickName,
          couponTitle: this.couponTitle,
          memberPhone: this.memberPhone,
          orderNo: this.orderNo,
          couponStatus: this.value
        }
      }).then(result => {
        this.dataList = result.data.list;
        this.total = parseInt(result.data.total);

        //console.log(this.dataList);
      });
    }
  }
};
</script>

<style scoped lang="scss">
.demo-input-suffix {
  margin-left: 2%;
}
.news {
  margin-left: 1%;
}
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
.tab {
  margin-top: 3%;
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.entirety {
  width: 95%;
  margin: 10px;
  border: 7px solid #fafafa;
  border-radius: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;

    margin-left: 1%;
  }
}

.input-with-select {
  width: 73%;
}
.down {
  width: 85px;
}

.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}

.top {
  font-size: 15px;
}

.big {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 3% 0 0;
}

.condition {
  width: 30%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  p {
    font-size: 14px;
  }
}
</style>
